package com.kuzan.autocloud.common.model.business;

import com.kuzan.autocloud.common.model.Base;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.Table;

/**
 * <p>Description: </p>
 *
 * @author kuzank
 */
@Data
@NoArgsConstructor
@Entity
@Table(name = "sys_business_item")
public class BusinessItem extends Base {

    /**
     * 别名
     */
    private String alias;
    /**
     * 所属业务
     */
    @Column(length = 32)
    private String business;
    /**
     * 类型: SQL查询, SQL执行, groovy脚本, ACTION转发
     * 所有类型产生的result均以item的ID作为KEY值注入到request中
     */
    @Column(length = 32)
    private String commandtype;
    /**
     * 是否输出结果
     */
    @Column(columnDefinition = "bit(1) default 1")
    private boolean output = true;
    /**
     * 参数
     */
    private String param;
    /**
     * 脚本
     */
    @Lob
    @Column(columnDefinition = "TEXT")
    private String script;


    public static BusinessItem of(String title, String business, String script, String id, String type, boolean output) {
        return of(title, business, script, id, type, null, output);
    }

    public static BusinessItem of(String title, String business, String script, String id, String type, String param, boolean output) {
        BusinessItem obj = new BusinessItem();
        obj.setTitle(title);
        obj.setBusiness(business);
        obj.setScript(script);
        obj.setId(id);
        obj.setCommandtype(type);
        obj.setParam(param);
        obj.setOutput(output);
        obj.setSort(getSortIncrement());
        return obj;
    }
}
